import combOptionApis from '../apis/combOptions'
import $ from 'jquery'
import _ from 'underscore'
import TimeStore from 'lib/stores/time-store'
function createApi(options){
  return combOptionApis(() => {
    var {spanTime, endTime} = TimeStore.getValue()
    endTime = endTime|| (new Date()).getTime()
    return _.extend({},options,{
      startTime:endTime - spanTime,
      endTime:endTime
    })
  })
}
export default {
  'crash':[{
    key:'appVersionId',
    name:'APP 版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:BlueWare.platform.toLowerCase()+'_crash',
        optionName:'appversion'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'osVersionId',
    name:'操作系统版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:BlueWare.platform.toLowerCase()+'_crash',
        optionName:'osversion'
      }).fetch().then((data) => {
        this.options = data.map((i) => {
          return {
            label:BlueWare.platform + ' ' + i.name,
            value:i.id
          }
        })
      })
    }
  },{
    key:'exceptionType',
    name:'崩溃类型',
    options:[],
    fetch:function(){
      return createApi({
        urlName:BlueWare.platform.toLowerCase()+'_crash',
        optionName:'exceptiontype'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  }],
  'httperror':[{
    key:'appVersionId',
    name:'APP版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httperror',
        optionName:'appversion'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'regionCodeId',
    name:'地域',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httperror',
        optionName:'region'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'statusCode',
    name:'状态码',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httperror',
        optionName:'statuscode'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'domainId',
    name:'域名',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httperror',
        optionName:'domain'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'osVersionId',
    name:'操作系统版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httperror',
        optionName:'osversion'
      }).fetch().then((data) => {
        this.options = data.map((i) => {
          return {
            label:BlueWare.platform + ' ' + i.name,
            value:i.id
          }
        })
      })
    }
  },{
    key:'netTypeId',
    name:'接入方式',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httperror',
        optionName:'nettype'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  }],
  'networkerror':[{
    key:'appVersionId',
    name:'APP版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'networkerror',
        optionName:'appversion'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'regionCodeId',
    name:'地域',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'networkerror',
        optionName:'region'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'errorCode',
    name:'故障类型',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'networkerror',
        optionName:'errorcode'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'domainId',
    name:'域名',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'networkerror',
        optionName:'domain'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'osVersionId',
    name:'操作系统版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'networkerror',
        optionName:'osversion'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'netTypeId',
    name:'接入方式',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'networkerror',
        optionName:'nettype'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  }],
  'httptransaction':[{
    key:'appVersionId',
    name:'APP版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httptransaction',
        optionName:'appversion'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'regionCodeId',
    name:'地域',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httptransaction',
        optionName:'region'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'domainId',
    name:'域名',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httptransaction',
        optionName:'domain'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'osVersionId',
    name:'操作系统版本',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httptransaction',
        optionName:'osversion'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  },{
    key:'netTypeId',
    name:'接入方式',
    options:[],
    fetch:function(){
      return createApi({
        urlName:'httptransaction',
        optionName:'nettype'
      }).fetch().then((data) => {
        this.options = data.map((i) =>({label:i.name,value:i.id}))
      })
    }
  }]
}
